#页面：搜索结果页
from selenium.webdriver.common.by import By

from utils.page_base import PageBase #导入页面基类

class PageSearchResult(PageBase):
    url="/index.php?controller=site&action=search_list&word="




    #功能：打开当前页面
    def openUrl(self):
        self.open(PageSearchResult.url)

    #功能：获取搜索结果中第一个商品的商品标题
    def getFirstGoodsTitle(self):
        ele_ul=self.driver.find_element_by_css_selector("section.goods_list > ul")
        eles_li=ele_ul.find_elements_by_css_selector("li")
        ele0=eles_li[0]
        ele_span=ele0.find_element_by_css_selector("p.goods_title > span")
        return ele_span.text.strip()


    #功能：获取“请输入正确的查询关键词”
    def getTipNull(self):
        ele1=self.driver.find_element_by_css_selector("i.ico + article > strong")
        return ele1.text.strip()

    #功能：判断搜索结果中所有商品的名称是否含有预期值
    def isExistsNameInGoodsName(self,yuqi):
        flag=True #默认：存在
        ele_ul = self.driver.find_element_by_css_selector("section.goods_list > ul")
        eles_li = ele_ul.find_elements_by_css_selector("li")
        for x in eles_li:
            ele_span = x.find_element_by_css_selector("p.goods_title > span")
            goodsName=ele_span.text.strip()
            if yuqi not in goodsName:
                flag=False #不存在
                break
        return flag

    #功能：没有找到任何商品
    def noGoods(self):
        loc=By.CLASS_NAME,"no_tip"
        return self.getText(loc)



